package notification

import (
	"fmt"

	"gitee.com/dayu1985/framework/context"
)

const SECTION_NOTIFICATION = "notification"

const SMS_TYPE_IHUYI = "ihuyi"
const SMS_TYPE_ALIYUN = "aliyun"
const SMS_TYPE_IENTINFO = "ientinfo"

func DefaultSMSNotification(c *context.Configuration) SMSNotification {

	t := c.INI.MustValue(SECTION_NOTIFICATION, "sms.type", "")

	switch t {
	case SMS_TYPE_IHUYI:

		a := c.INI.MustValue(SECTION_NOTIFICATION, "ihuyi.account", "")
		p := c.INI.MustValue(SECTION_NOTIFICATION, "ihuyi.password", "")

		return NewIHuyiSMSNotification(a, p)

	case SMS_TYPE_ALIYUN:

		s := c.INI.MustValue(SECTION_NOTIFICATION, "aliyun.sign", "<签名>")
		a := c.INI.MustValue(SECTION_NOTIFICATION, "aliyun.key", "<授权ID>")
		p := c.INI.MustValue(SECTION_NOTIFICATION, "aliyun.secret", "<授权码>")

		return NewIAliSMSNotification(s, a, p)

	case SMS_TYPE_IENTINFO:

		d := c.INI.MustValue(SECTION_NOTIFICATION, "ientinfo.domian", "http://sdk.entinfo.cn:8061/webservice.asmx/mdsmssend")
		s := c.INI.MustValue(SECTION_NOTIFICATION, "ientinfo.sn", "<软件序列号>")
		p := c.INI.MustValue(SECTION_NOTIFICATION, "ientinfo.pwd", "<密码>")

		return NewIEntInfoSMSNotification(d, s, p)

	default:
		panic(fmt.Sprintf("不支持的短信接口类型. sms.type = %s", t))
	}
}
